package com.isoft.controll;

import com.isoft.menu.Menu;
import com.isoft.pojo.Goods;
import com.isoft.service.GoodsService;

import java.util.Scanner;

public class GoodsController {
    Scanner scanner;//输入流
    //alt+insert    / alt+fn+ins
    GoodsService goodsService;
    public GoodsController() {
        scanner = new Scanner(System.in);//实例化对象
        goodsService=new GoodsService();
    }

    public void startSystem(){

        try {Goods goods = new Goods();
            String goodsId="";//运行时输入
            do {

                Menu.sysMenu();
                String userSelect=scanner.next();
                switch (userSelect){
                    case "1":
                        goods=new Goods();
                        System.out.print("请输入商品ID:");
                        String id= scanner.next();
                        System.out.print("请输入商品名称：");
                        String goodsName= scanner.next();
                        System.out.print("请输入商品类型：");
                        String goodsType= scanner.next();
                        System.out.print("请输入商品库存：");
                        int inventory= scanner.nextInt();
                        System.out.print("请输入商品单价：");
                        double price= scanner.nextDouble();
                        goods.setGoodsId(id);
                        goods.setGoodsName(goodsName);
                        goods.setGoodsType(goodsType);
                        goods.setInventory(inventory);
                        goods.setPrice(price);
                        goodsService.addGoods(goods);
                        break;
                    case "2":
                        System.out.print("请输入要删除的商品ID:");
                        goodsId=scanner.next();
                        goodsService.deleteGoods(goodsId);
                        break;
                    case "3":
                        goods=new Goods();
                        goodsService.updateGoods(goods);
                        break;
                    case "4":
                        System.out.print("请输入要查询的商品ID:");
                        goodsId=scanner.next();
                        goodsService.findGoodsByID(goodsId);
                        break;
                    case "5":
                        exit();
                        break;

                }
                System.out.println("按任意键继续...");
                System.in.read();//阻塞方法，等待用户输入
            } while (true);

        }catch (Exception e){
            e.printStackTrace();
            System.out.println("系统出错了，请重试");
        }
    }
public void exit(){

}
}
